package cn.tedu.tmall.front.mall.dao.persist.repository.impl;

import cn.tedu.tmall.common.pojo.vo.PageData;
import cn.tedu.tmall.common.util.PageInfoToPageDataConverter;
import cn.tedu.tmall.front.mall.dao.persist.mapper.CategoryMapper;
import cn.tedu.tmall.front.mall.dao.persist.repository.ICategoryRepository;
import cn.tedu.tmall.front.mall.pojo.vo.CategoryListItemVO;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 处理类别数据的存储库实现类
 *
 * @author java@tedu.cn
 * @version 3.0
 */
@Slf4j
@Repository
public class CategoryRepositoryImpl implements ICategoryRepository {

    @Autowired
    private CategoryMapper categoryMapper;

    public CategoryRepositoryImpl() {
        log.info("创建存储库对象：CategoryRepositoryImpl");
    }

    @Override
    public List<CategoryListItemVO> list() {
        log.debug("开始执行【查询类别列表】的数据访问，参数：无");
        return categoryMapper.list();
    }

    @Override
    public PageData<CategoryListItemVO> listByParent(Long parentId, Integer pageNum, Integer pageSize) {
        log.debug("开始执行【根据父级类别查询其子级类别列表】的数据访问，父级类别：{}，页码：{}，每页记录数：{}", parentId, pageNum, pageSize);
        PageHelper.startPage(pageNum, pageSize);
        List<CategoryListItemVO> list = categoryMapper.listByParent(parentId);
        PageInfo<CategoryListItemVO> pageInfo = new PageInfo<>(list);
        return PageInfoToPageDataConverter.convert(pageInfo);
    }

}
